package controllers

import (
	"github.com/goravel/framework/contracts/http"
	"github.com/goravel/framework/facades"
	"github.com/goravel/framework/support/path"
	"goravel/app/models"
	. "goravel/app/services"
	"io/ioutil"
)

type ParseController struct {
	//Dependent services
	parsePrylockLogService   *ParsePrylockLogService
	parseKillLogService      *KillLogService
	parseLoginLogService     *LoginLogService
	parseChatLogService      *ChatLogService
	parseAdminLogService     *AdminLogService
	parseViolationLogService *ViolationLogService
	//parseCodeService         *ParseCodeService
	parseMineLogService     *MineLogService
	parseLandFlagLogService *LandFlagLogService
	parseTradeLogService    *TradeLogService
	parseBankLogService     *BankLogService
	parseBatchService       *BatchService
}

func NewParseController() *ParseController {
	return &ParseController{
		//Inject services
	}
}

// 获取文件方法
func (r *ParseController) getLogFile(foldName string) []string {
	pathname := path.Public(foldName)
	//		获取目录下的所有文件
	files, _ := ioutil.ReadDir(pathname)

	var fileList []string
	for _, f := range files {
		fileList = append(fileList, f.Name())
	}
	return fileList
}

// 返回文件夹路径和配置id
func (r *ParseController) getPath(ctx http.Context) (string, uint) {
	port := ctx.Request().Input("port")
	hostname := ctx.Request().Input("host")
	username := ctx.Request().Input("username")
	server_name := ctx.Request().Input("server_name")
	type_name := ctx.Request().Input("type")
	if server_name == "GG_Host" {
		type_name = "sftp"
	} else {
		type_name = "ftp"
	}
	foldPath := type_name + "/" + hostname + "/" + port + "/" + username + "/"
	var config models.Configuration
	facades.Orm().Query().Model(&models.Configuration{}).Where("server_name", server_name).
		Where("type", type_name).First(&config)
	return foldPath, config.ID
}
